SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE VIEW dbo.DnnProduct_vw_Modules
AS
    SELECT     
        M.PortalID, 
        TM.TabID, 
        TM.TabModuleID, 
        M.ModuleID, 
        M.ModuleDefID, 
        TM.ModuleOrder, 
        TM.PaneName, 
        TM.ModuleTitle, 
        TM.CacheTime, 
        TM.CacheMethod, 
        TM.Alignment, 
        TM.Color, 
        TM.Border, 
        CASE WHEN LEFT(LOWER(TM.IconFile), 6) = 'fileid' THEN (SELECT Folder + FileName FROM dbo.DnnProduct_Files WHERE 'fileid=' + CONVERT(varchar, dbo.DnnProduct_Files.FileID) = TM.IconFile) ELSE TM.IconFile END AS IconFile, 
        M.AllTabs, 
        TM.Visibility, 
        TM.IsDeleted, 
        TM.Header, 
        TM.Footer, 
        M.StartDate, 
        M.EndDate, 
        TM.ContainerSrc, 
        TM.DisplayTitle, 
        TM.DisplayPrint, 
        TM.DisplaySyndicate, 
        TM.IsWebSlice, 
        TM.WebSliceTitle, 
        TM.WebSliceExpiryDate, 
        TM.WebSliceTTL, 
        M.InheritViewPermissions, 
        MD.DesktopModuleID, 
        MD.DefaultCacheTime, 
        MC.ModuleControlID, 
        DM.BusinessControllerClass, 
        DM.IsAdmin, 
        DM.SupportedFeatures,
        CI.ContentItemID,
        CI.Content,
        CI.ContentTypeID,
        CI.ContentKey,
        CI.Indexed,
        M.CreatedByUserID, 
        M.CreatedOnDate, 
        M.LastModifiedByUserID, 
        M.LastModifiedOnDate,
        M.LastContentModifiedOnDate,
        TM.UniqueId, 
        TM.VersionGuid, 
        TM.DefaultLanguageGuid, 
        TM.LocalizedVersionGuid,
        TM.CultureCode
    FROM dbo.DnnProduct_ModuleDefinitions AS MD 
        INNER JOIN dbo.DnnProduct_Modules AS M ON MD.ModuleDefID = M.ModuleDefID 
        INNER JOIN dbo.DnnProduct_ModuleControls AS MC ON MD.ModuleDefID = MC.ModuleDefID 
        INNER JOIN dbo.DnnProduct_DesktopModules AS DM ON MD.DesktopModuleID = DM.DesktopModuleID 
        LEFT OUTER JOIN dbo.DnnProduct_ContentItems AS CI ON M.ContentItemID = CI.ContentItemID
        LEFT OUTER JOIN dbo.DnnProduct_TabModules AS TM ON M.ModuleID = TM.ModuleID
    WHERE (MC.ControlKey IS NULL)

GO
